package com.xxx.modules.controller;

import com.github.pagehelper.PageInfo;
import com.xxx.modules.entity.Comment;
import com.xxx.modules.service.CommentService;
import com.xxx.modules.utils.Result;
import com.xxx.modules.utils.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * comment
 *  留言管理
 *
 * @author 北易航
 * @since 1.0.0 2022-12-19
 */
@RestController
@RequestMapping("/common/comment")
@Api(tags="comment")
public class CommentController {
    @Autowired
    private CommentService commentService;

    /**
    *  查询所有comment
    * @param pageNum
    * @param pageSize
    * @param comment
    * @return
    */

    @GetMapping("/getCommentInfo")
    @ApiOperation("获取所有评论")
    public Result getCommentInfo(Comment comment, @RequestParam(value="pageNum",defaultValue = "1") Integer pageNum,
                                      @RequestParam(value="pageSize",defaultValue = "10") Integer pageSize,
                                      @RequestParam(value = "id") Integer id){
        PageInfo<Comment> data = commentService.selectCommentInfo(comment,pageNum,pageSize);
        List<Comment> comments = this.commentService.getListByPage(id);
        PageInfo<Comment> commentsPageInfo = new PageInfo<>(comments);

//        IPage<Comment> page = new Page<>(pageNum,pageSize);
////
//////        PageInfo<Comment> data = commentService.selectCommentInfo(comment,pageNum,pageSize);
////        QueryWrapper<Comment> queryWrapper = new QueryWrapper<>();
////        if (!StringUtils.isEmpty(id)){
////            queryWrapper.like("notice_id",id);
////        }
////       IPage<Comment> page1 = commentService.page(page,queryWrapper);
        return ResultUtil.success(1,"成功",commentsPageInfo);
    }

    /**
    * 保存comment
    * @param comment
    * @return
    */
    @PostMapping("/saveCommentInfo")
    @ApiOperation("保存留言")
    public Result saveCommentInfo(@RequestBody Comment comment){
        commentService.saveCommentInfo(comment);
        return ResultUtil.success(1,"成功",null);
    }


    /**
     * 更新comment
     * @param comment
     * @return
     */

    @PutMapping("/updateCommentInfo")
    @ApiOperation("更新")
    public Result updateCommentInfo(@RequestBody Comment comment){
        commentService.updateCommentInfo(comment);
        return ResultUtil.success(1,"成功",null);
    }

    /**
     * 根据id删除Comment
     * @param id
     * @return
     */
    @DeleteMapping("/delCommentInfo")
    public Result delCommentInfo(Integer id){
        commentService.delCommentInfo(id);
        return ResultUtil.success(1,"成功",null);
    }

    /**
     * 根据id集合删除comment
     * @param idList
     * @return
     */
    @DeleteMapping("/delBatchCommentInfo")
    public Result delBatchCommentInfo(String idList){
        commentService.delBatchCommentInfo(idList);
        return ResultUtil.success(1,"成功",null);
    }

}